<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../static/css/base.css"/>
    <link rel="stylesheet" href="../static/css/drag.css"/>
    <link rel="stylesheet" href="../static/css/index.css"></link>

</head>
<body>
<%--<div class="head" style="background-image: url(../img/bg_header_index_top.png); height: 50px">--%>
<%--    <div class="container-fluid">--%>
<%--        <!-- Brand and toggle get grouped for better mobile display -->--%>
<%--        <div class="navbar-header">--%>
<%--            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"--%>
<%--                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">--%>
<%--                <span class="sr-only">Toggle navigation</span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--            </button>--%>
<%--            <a class="navbar-brand" href="#">此处是logo</a>--%>
<%--        </div>--%>

<%--        <!-- Collect the nav links, forms, and other content for toggling -->--%>
<%--        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">--%>
<%--            <ul class="nav navbar-nav" style="margin-right: 2px">--%>
<%--                <li><a href="#">首页</a></li>--%>
<%--                <li><a href="http://localhost:8888/html/allhotel.html">国内酒店</a></li>--%>
<%--                <li><a href="#">国外酒店</a></li>--%>
<%--                <li><a href="#">特卖专区</a></li>--%>
<%--                <li class="active"><a href="http://localhost:8888/html/index.html">旗下品牌</a></li>--%>
<%--                <li><a href="#">华住会</a></li>--%>
<%--                <li><a href="#">华住商旅</a></li>--%>
<%--            </ul>--%>

<%--            <ul class="nav navbar-nav navbar-right">--%>
<%--                <li style="margin-right: 30px;margin-top: 10px">--%>
<%--                    <button type="button" class="btn btn-primary small " style=";height: 30px;width:70px">登录</button>--%>
<%--                </li>--%>
<%--                <li style="margin-right: 30px;margin-top: 10px">--%>
<%--                    <button type="button" class="btn btn-default small active" style=";height: 30px;width:70px">注册--%>
<%--                    </button>--%>
<%--                </li>--%>
<%--            </ul>--%>
<%--        </div>--%>
<%--    </div>--%>
<%--</div>--%>
<div id="top1" class="container-fluid">
    <div class="row" style="margin-left: 5%;margin-right: 5%">
        <nav class="navbar" role="navigation">
            <div class="container-fluid" >
                <div class="navbar-header">
                    <p class="navbar-brand" style="font-size: 30px;">忘记密码</p>
                </div>
                <div class="collapse navbar-collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#">了解更多</a>
                        </li>
                        <li>
                            <a href="#">反馈信息</a>
                        </li>
                        <li>
                            <a href="#">english</a>
                        </li>
                    </ul>

                </div>
            </div>
        </nav>
    </div>
</div>
<div class="container-fluid">
    <div class="row col-md-12" style="margin-top: 60px;">
        <div class="col-md-5 col-md-offset-1">
            <form class="form-horizontal" id="form1" action="">
                <div class="form-group inputpadding">
                    <label for="input1" class="col-sm-2 control-label">邮箱</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="email" id="input1" placeholder="绑定的邮箱">
                    </div>
                </div>
                <div class="form-group inputpadding">
                    <label for="input2" class="col-sm-2 control-label">验证码</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="emailcode" id="input2" placeholder="邮箱的验证码">
                    </div>
                    <div class="col-sm-5">
                        <button type="button" class="btn" id="button1" onclick="drag()">获取验证码</button>
                        <div id="dragContainer" style="display: none"><!-- 容器初始背景 -->
                            <div id="dragBg"></div><!-- 绿色背景 -->
                            <div id="dragText"></div><!-- 滑动容器文本 -->
                            <div id="dragHandler" class="dragHandlerBg"></div>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-danger col-md-12" onclick="emaillogin()">Sign in</button>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <p id="warningtip" class="col-md-12" style="text-align: center;color: red" ></p>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-md-offset-2 col-md-3">
            <p class="textpadding">还未注册？<button class="btn" onclick="regist()">点击注册</button></p>
            <p class="textpadding">使用合作网站账号登录：<br/>
                <button class="btn btn-danger" style="width: 40%">qq登录</button>
                <button class="btn btn-primary" style="width: 40%">wb登录</button>
                <br/>
                <button class="btn btn-info" style="width: 40%">al登录</button>
                <button class="btn btn-success" style="width: 40%">wx登录</button>
            </p>
            <p class="textpadding">您可以使用航空公司/银行卡快速注册<br/>
                <button class="btn">合作卡登录</button></p>
            <p class="textpadding">您也可以为企业申请公司会员办卡<br/>
                <button class="btn">企业卡申请</button></p>
        </div>
    </div>
</div>

<div class="container-fluid">
    <div class="row" style="margin-top: 30px; background-color: #f5f5f5;height: 110px;" >
        <div class="col-md-6 col-md-offset-3" >
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">网站介绍</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">酒店加盟</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">职位招聘</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">意见反馈</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">联系我们</a>
            </div>
        </div>

    </div>

</div>

<script src="../static/bootstrap/js/jquery-3.3.1.js"></script>
<script>


    function drag() {


        if ($('#input1').val()==""){
            return
        }
        $('#button1').css('display','none')
        $('#dragContainer').css('display','inline-block')
        //获取滑动控件容器,灰色背景
        var dragContainer = document.getElementById("dragContainer");
        //获取滑块左边部分,绿色背景
        var dragBg = document.getElementById("dragBg");
        //获取滑动验证容器文本
        var dragText = document.getElementById("dragText");
        //获取滑块
        var dragHandler = document.getElementById("dragHandler");

        //滑块的最大偏移量                 =     滑动验证容器文本长度                  -      滑块长度
        var maxHandlerOffset = dragContainer.clientWidth - dragHandler.clientWidth;
        //是否验证成功的标记
        var isVertifySucc = false;


        initDrag();
        var left = 0;

        var intval1
        var intval2

        function initDrag() {
            //在滑动验证容器文本写入“拖动滑块验证”

            dragText.textContent = "按住滑块验证";
            //给滑块添加鼠标按下监听
            dragHandler.addEventListener("mousedown", onDragHandlerMouseDown);
        }

        //选中滑块
        function onDragHandlerMouseDown() {
            clearInterval(intval2)
            clearInterval(intval1)

            intval1 = setInterval(function(){
                left += 4
                if(left > maxHandlerOffset) {
                    left = maxHandlerOffset;
                    verifySucc();
                }
                //滑块移动量
                dragHandler.style.left = left + "px";
                //绿色背景的长度
                dragBg.style.width = dragHandler.style.left;

            },25)

            //鼠标松开监听
            document.addEventListener("mouseup",  onDragHandlerMouseUp);
        }


        //松开滑块函数
        function onDragHandlerMouseUp() {

            clearInterval(intval1)
            clearInterval(intval2)

            //移除鼠标松开监听
            document.removeEventListener("mouseup", onDragHandlerMouseUp);

            intval2 = setInterval(function(){
                left -= 4
                dragHandler.style.left = left + "px";
                //初始化绿色背景
                dragBg.style.width = dragHandler.style.left;
                if (left==0){
                    clearInterval(intval2)
                }

            },25)


        }

        //验证成功
        function verifySucc() {

            //成功标记，不可回弹
            isVertifySucc = false;
            //容器文本的文字改为白色“验证通过”字体
            dragText.textContent = "验证通过";
            dragText.style.color = "white";
            //验证通过的滑块背景
            dragHandler.setAttribute("class", "dragHandlerOkBg");
            //移除鼠标按下监听
            dragHandler.removeEventListener("mousedown", onDragHandlerMouseDown);
            //移除鼠标松开监听
            document.removeEventListener("mouseup", onDragHandlerMouseUp);
            // 匹配成功
            clearInterval(intval1)
            clearInterval(intval2)
            setTimeout(function () {


                $('#dragContainer').css('display','none')
                isVertifySucc = true;
                dragHandler.setAttribute("class", "dragHandlerBg");
                $('#button1').css('display','block')
                $('#button1').attr('disabled','true')
                $('#button1').text('发送邮件中')


                $.ajax({
                    url:"/user/email?email="+$('#input1').val(),
                    type:"get",
                    dataType:"text",
                    success:function (data) {
                        if(data=="fail"){
                            $('#button1').text('发送失败')
                            $("#warningtip").text("邮箱未绑定")
                            setTimeout(function () {
                                $('#button1').attr('disabled','false')
                                $('#button1').text('发送验证码')
                            },5000)
                        } else {
                            $('#button1').text('验证码已发送')
                            setTimeout(function () {
                                $('#button1').attr('disabled','false')
                                $('#button1').text('发送验证码')
                            },60000)
                        }
                    }
                })


            },3000)


        };
    }


    function regist() {

        location.href = "/regist"
    }

    function emaillogin(){
        $("#warningtip").text("")

        var email = $('#input1').val()
        var code = $('#input2').val()

        if(email=="undefine"||email==""||code=="undefine"||code==""){
            $("#warningtip").text("邮箱或验证码不能为空")
            return;
        }
        console.log(email)
        console.log(code)

        var formData = new FormData();
        formData.append("email",email)
        formData.append("code",code)

        $.ajax({
            url:"/user/emaillogin",
            type:"post",
            processData: false, //jquery 是否对数据进行 预处理
            contentType: false, // 不要自己修改请求内容类型,
            data:formData,
            dataType:"text",
            success:function (data) {
                if(data=="success"){
                    alert("邮箱登录成功")
                    setTimeout(function () {
                        window.location.href="/user/emailpwd"
                    },1000)


                } else if(data=="fail"){
                    $("#warningtip").text("验证码错误")
                }
            }
        })
    }

</script>

</body>
</html>